<?php if (!defined("_ECRIRE_INC_VERSION")) return; if (class_exists('AlohacartShippingNovaposhta')) return;
/**
 * Aloha Cart
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage alohacart
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/AlohaCart
 */

/** 
 *  This class provides Novaposhta shipping logic
 *
 *  @author Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 */
include_spip('functions/pdk_common');
pdk_load_class('AlohacartExtension', 'classes'); 
class AlohacartShippingNovaposhta extends AlohacartExtension {
    public $fields = array('cost', 'id_currency');
    
    public function __construct() {
        parent::__construct();
        $this->configExtension();
    }
    
    private function configExtension(){
        $this->type = 'shipping';
        $this->code = 'novaposhta';
        
        // Define validation rules:         
         $this->validation->set_rules( 
            array(
            )
         );
    }
    
    /**
     *  Gets shipping cost in main currency
     */
    public function GetCost() {
        $data = $this->GetMetaData();
        $cost = isset($data['cost'])?$data['cost']:0;
        // Shipping cost may be stored in any currency, so we will convert it into main currency		
        if ($data['id_currency'])
            $cost = $this->currency_mdl->ConvertPriceToMainCurrency($cost, $data['id_currency']);
		
		return parent::ModifyCost($cost);
    }
    
    /**
     * Gets shipping data (info) wich is outputed for user
     */
    public function GetData() {
        $cost = $this->GetCost();
        $currency = $this->currency_mdl->GetCurrentCurrency();
        $data = '';
        if ($cost)
            $data = extraire_multi($currency['sign_pre']).' '.$cost.' '.extraire_multi($currency['sign_after']).'. ';
        return parent::ModifyData($data);
    }
}
?>